﻿@using PlatformNetCore.Entity
@{
    ViewBag.Title = "新增管理员";
}
@model SysUser
<style>
    html {
        background-color:#fff;
    }
    .layui-card {
        box-shadow:none;
    }
</style>
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="@Url.Action("UserAdd","Sys",new { area = "Admin"})" lay-filter="useradd-form">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="Login" lay-verify="required" placeholder="请输入用户名" autocomplete="on" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="password" name="Pwd" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属角色</label>
                <div class="layui-input-block">
                    <select name="RoleId" lay-filter="RoleId">
                        @foreach (var item in (IEnumerable<SelectListItem>)ViewBag.RoleDLL)
                        {
                            <option value="@item.Value">@item.Text</option>
                        }
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="IsAvailable" value="1" lay-skin="switch" lay-filter="component-form-switchTest" lay-text="启用|禁用">
                </div>
            </div>
            <div id="useradd-submit" lay-submit lay-filter="useradd-submit"></div>
        </form>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        var $ = layui.$, form = layui.form;

        form.render(null, 'useradd-form');

        /* 自定义验证规则 */
        form.verify({
            UserName: function (value) {
                if (value.length < 5) {
                    return '用户名至少5个字符';
                }
            }
            , Pwd: [/(.+){6,20}$/, '密码必须6到20位']
        });

        /* 监听指定开关 */
        form.on('switch(component-form-switchTest)', function (data) {
            $(this).val(this.checked ? '1' : '0')
        });

    });
</script>
